<template>
  <!--  出勤申请 -->
  <div class="Apply">
    <!-- 头部 --state-->
    <div class="side_1"></div>
    <span class="add_1">申请</span>
    <el-button type="info" class="btn_fanhui" icon="el-icon-back" @click="Fh">返回</el-button>
    <!-- 头部 --end-->
    <!-- 表格 --start-->

    <div class="body">
      <div class="form_body">
        <div class="div_title">
          <span>申请</span>
        </div>
        <div class="con">
          <div class="wrap">
            <span class="consty" style="width:119px;border-right: 1px solid #eee;">申请类型</span>
            <span class="consty" style="width:680px;">
              <el-select class="inputclass" v-model="typeVal" placeholder="调休申请" @change="change">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </span>
          </div>
          <div class="wrap">
            <span
              v-if="state1"
              class="consty"
              style="width:119px;border-right: 1px solid #eee;"
            >请假时间</span>
            <span class="consty" style="width:680px;" v-if="state1">
              <el-date-picker
                class="inputclass"
                v-model="date1"
                type="datetimerange"
                align="right"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy-MM-dd HH:mm"
                value-format="yyyy-MM-dd HH:mm"
              ></el-date-picker>
            </span>
            <span
              v-if="state2"
              class="consty"
              style="width:119px;border-right: 1px solid #eee;"
            >出差时间</span>
            <span class="consty" style="width:680px;" v-if="state2">
              <el-date-picker
                class="inputclass"
                v-model="date2"
                type="datetimerange"
                align="right"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy-MM-dd HH:mm"
                value-format="yyyy-MM-dd HH:mm"
              ></el-date-picker>
            </span>
            <span
              v-if="state3"
              class="consty"
              style="width:119px;border-right: 1px solid #eee;"
            >加班时间</span>
            <span class="consty" style="width:680px;" v-if="state3">
              <el-date-picker
                class="inputclass"
                v-model="date3"
                type="datetimerange"
                align="right"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy-MM-dd HH:mm"
                value-format="yyyy-MM-dd HH:mm"
              ></el-date-picker>
            </span>
          </div>
          <div class="wrap" v-if="state1">
            <span class="consty" style="width:119px;border-right: 1px solid #eee;">请假天数</span>
            <span class="consty" style="width:680px;">
              <el-input
                class="inputclass"
                v-model="days"
                placeholder="请假天数"
                style="width:583px;margin:0 5px 0 0"
              ></el-input>天
            </span>
          </div>
          <div class="wrap" v-if="state1">
            <span class="consty" style="width:119px;border-right: 1px solid #eee;">请假类型</span>
            <span class="consty" style="width:680px;">
              <el-radio-group v-model="leaveType">
                <el-radio
                  :label="item.value"
                  v-for="item in leaveoptions"
                  :key="item.value"
                >{{item.label}}</el-radio>
              </el-radio-group>
            </span>
          </div>
          <div class="wrap" v-if="state2">
            <span class="consty" style="width:119px;border-right: 1px solid #eee;">出差时长</span>
            <span class="consty" style="width:280px;">
              <el-input
                v-model="chuchailong"
                class="inputinput"
                style="margin:0 5px 0 0"
                placeholder="出差时长"
              ></el-input>天
            </span>
            <span
              class="consty"
              style="width:118px;border-right: 1px solid #eee;border-left: 1px solid #eee;"
            >出差地点</span>
            <span class="consty" style="width:280px;">
              <el-input
                v-model="chuchaiaddress"
                class="inputinput"
                style="margin:0"
                placeholder="出差地点"
              ></el-input>
            </span>
          </div>
          <div class="wrap" v-if="state3">
            <span class="consty" style="width:119px;border-right: 1px solid #eee;">加班时长</span>
            <span class="consty" style="width:680px;">
              <el-input
                class="inputclass"
                v-model="jiabanlong"
                placeholder="加班时长"
                style="width:583px;margin:0 5px 0 0"
              ></el-input>时
            </span>
          </div>
          <div class="wrap">
            <span
              style="width:119px;display: inline-block; vertical-align: middle;font-size: 14px;"
            >事由</span>
            <span
              style="width:680px;display: inline-block; vertical-align: middle;font-size: 14px;border-left: 1px solid #eee;padding:10px 0;"
            >
              <el-input
                style="font-size:14px;"
                class="inputclass"
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 4}"
                placeholder="请输入事由"
                v-model="reason"
              ></el-input>
            </span>
          </div>
        </div>
      </div>
    </div>
    <div class="btn_bottom">
      <el-button type="primary" size="medium" @click="queDing">确定</el-button>
      <el-button type="info" size="medium" @click="quXiao">返回</el-button>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data () {
    return {
      options: [{ value: 1, label: "请假" }, { value: 2, label: "出差" }, { value: 3, label: "加班" }],
      typeVal: "请假",
      type: 1,
      state1: true,
      state2: false,
      state3: false,
      date1: "",
      date2: "",
      date3: "",
      days: "",//请假天数
      leaveType: 1,//请假类型
      leaveoptions: [{ value: 1, label: "事假" }, { value: 2, label: "病假" }, { value: 3, label: "婚假" }, { value: 4, label: "产假" }, { value: 5, label: "年假" }, { value: 6, label: "其他" }],
      reason: "",//事由
      chuchailong: "",//出差时长
      chuchaiaddress: "",//出差地点
      jiabanlong: "",//加班时长
      creater: 0,
      Mark: 0
    };
  },
  created () {
    this.creater = JSON.parse(localStorage.getItem("message")).Id;
  },
  methods: {
    Fh () {
      window.history.go(-1);
    },
    quXiao () {
      window.history.go(-1);
    },
    change (e) {
      this.type = e;
      this.state1 = false; this.state2 = false; this.state3 = false;
      if (e == 1) { this.state1 = true; } else if (e == 2) { this.state2 = true; } else if (e == 3) { this.state3 = true; }
    },
    //申请
    //type==1请假 ；type==2 出差；type==3 加班
    queDing () {
      if (this.Mark == 0) {
        let obj = {};
        if (this.type == 1) {
          if (this.date1 == null || this.date1 == "") { this.$message.error("请假时间非空"); return; }
          if (this.days == "") { this.$message.error("请假天数非空"); return; }
          if (this.reason == "") { this.$message.error("事由非空"); return; }
          obj = { type: this.type, startTime: this.date1[0], endTime: this.date1[1], howLong: this.days, leaveType: this.leaveType, reason: this.reason, creater: this.creater }
        }
        else if (this.type == 2) {
          if (this.date2 == null || this.date2 == "") { this.$message.error("出差时间非空"); return; }
          if (this.chuchailong == "") { this.$message.error("出差时长非空"); return; }
          if (this.chuchaiaddress == "") { this.$message.error("出差地点非空"); return; }
          if (this.reason == "") { this.$message.error("事由非空"); return; }
          obj = { type: this.type, startTime: this.date2[0], endTime: this.date2[1], howLong: this.chuchailong, chuchaiaddress: this.chuchaiaddress, reason: this.reason, creater: this.creater }
        }
        else if (this.type == 3) {
          if (this.date3 == null || this.date3 == "") { this.$message.error("加班时间非空"); return; }
          if (this.jiabanlong == "") { this.$message.error("加班时长非空"); return; }
          if (this.reason == "") { this.$message.error("事由非空"); return; }
          obj = { type: this.type, startTime: this.date3[0], endTime: this.date3[1], howLong: this.jiabanlong, reason: this.reason, creater: this.creater }
        }
        var objs = JSON.stringify(obj);
        console.log(objs);
        let the = { index: 3, jsondata: objs };
        this.Mark = 1;
        axios.post("/apis/MyCenter.asmx/Add", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          console.log(list);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);
          } else {
            this.$message.error(list.tip);
          }
        });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
.side_1 {
  width: 5px;
  height: 16px;
  background-color: $Header_color;
  margin-left: 10px;
  margin-top: 30px;
}
.add_1 {
  margin-left: 20px;
  margin-top: -20px;
  float: left;
  font-size: 18px;
  font-weight: 400;
}
.btn_fanhui {
  margin-top: -20px;
  margin-right: 20px;
  float: right;
}
.body {
  width: 98%;
  // height: 900px;
  margin-top: 40px;
  margin-left: 20px;
  background: $white;
  overflow: hidden;
}

.form_body {
  margin-top: 80px;
  width: 800px;
  margin: 0 auto;
  padding: 100px 0;
}
.wrap {
  font-size: 0;
  text-align: center;
  width: 800px;
  border-top: 1px solid #eee;
  margin-top: -1px;
}
.consty {
  display: inline-block;
  vertical-align: middle;
  font-size: 14px;
  height: 50px;
  line-height: 50px;
}
.inputclass {
  width: 600px;
  font-size: 14px;
}
.inputinput {
  margin: 0;
}
.div_title {
  border: 1px solid $bordercolor;

  height: 80px;
  line-height: 80px;
  text-align: center;
  font-size: 18px;
  color: #333333;
  font-weight: 700;
}
.con {
  border: 1px solid $bordercolor;
  border-top: none;
}
.btn_bottom {
  margin-top: 30px;
  margin-left: 45%;
}

.el-input {
  width: 62%;
  margin: 10px 0px;
}
.table {
  width: 800px;
}
table,
table tr th {
  height: 60px;
}
table tr td {
  border: 1px solid #e7e7e7;
  border-top: 0.5px;
  text-align: center;
}

.line {
  margin-top: 18px;
}
</style>

